package com.monitor.service.parser.impl;

import com.monitor.model.ServerStatus;
import com.monitor.service.parser.MetricParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 系统负载指标解析器
 * 负责解析系统负载情况
 */
public class SystemLoadMetricParser implements MetricParser {
    private static final Logger logger = LoggerFactory.getLogger(SystemLoadMetricParser.class);

    @Override
    public void parse(String commandOutput, ServerStatus status) {
        try {
            String[] loads = commandOutput.trim().split("\\s+");
            if (loads.length >= 3) {
                status.setSystemLoad(String.format("%s, %s, %s (1分钟, 5分钟, 15分钟)", 
                    loads[0], loads[1], loads[2]));
            }
        } catch (Exception e) {
            logger.error("解析系统负载失败: {}", e.getMessage());
            status.setSystemLoad("解析错误");
        }
    }
} 